package com.ruikong.dazhi.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 开启拦截器
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {


    //IOC注入 方法二
    @Bean
    public HandlerInterceptor getUserInterceptor(){
        return new CpiInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        registry.addInterceptor(getUserInterceptor())
                .addPathPatterns("/data/**").excludePathPatterns("/data/login")//拦截除登录数据请求的所有接口
                .addPathPatterns("/view/**").excludePathPatterns("/view/login");//拦截除登录页面的所有页面
        WebMvcConfigurer.super.addInterceptors(registry);
    }
}
